<template>
    <div>
    <!-- 添加员工信息 -->
        <el-form style="max-width: 600px" :model="empDate" :rules="rules()" class="demo-ruleForm">
            <el-form-item label="账号" prop="account">
                <el-input v-model="empDate.account" placeholder="请输入账号" />
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input v-model="empDate.password" placeholder="请输入密码" />
            </el-form-item>
            <el-form-item label="昵称" prop="nickname">
                <el-input v-model="empDate.nickname" placeholder="请输入昵称" />
            </el-form-item>
            <el-form-item label="手机号" prop="telephone">
                <el-input v-model="empDate.telephone" placeholder="请输入手机号" />
            </el-form-item>
            <el-form-item label="角色" prop="role">
                <el-input v-model="empDate.role" placeholder="请输入角色" />
            </el-form-item>
            <el-form-item label="状态" prop="isDel">
                <el-select v-model="empDate.isDel" placeholder="请输入状态">
                    <el-option label="正常" value="0" />
                    <el-option label="禁用" value="1" />
                    <el-option label="离职" value="2" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="addEmp()">
                    提交
                </el-button>
                <el-button @click="">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import axios from "axios";
import qs from "qs";
export default {
    data() {
        return {
            empDate: {
                account: "",
                password: "",
                nickname: "",
                telephone: "",
                role: "",
                isDel: ""
            },
            // 后端服务器路径
            lastUrl: "http://localhost:8080/emp"
        }

    },
    methods: {
        // 校验添加的信息
        rules() { },
        cancel(){
            this.empDate = {
                        account: "",
                        password: "",
                        nickname: "",
                        telephone: "",
                        role: "",
                        isDel: ""
                    };
        },
        addEmp() {
            axios({
                method: "post",
                url: this.lastUrl + "/addEmp",
                data: qs.stringify(this.empDate),
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                }
            }).then(
                resp => {
                    console.log(resp);
                    ElMessage({
                        message: '添加成功',
                        type: 'success',
                    });
                    this.cancel();
                })

        }
    }
}
</script>

<style scoped></style>